package org.NooLab.itexx.app.controller.results;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;


import org.NooLab.itexx.stuctures.RequestFocusSpec;
import org.NooLab.utilities.logging.PrintLog;
import org.NooLab.utilities.net.GUID;
import org.NooLab.utilities.strings.StringsUtil;





public class SearchEngineResultItem 
										implements 
														SearchEngineResultItemIntf,
														Serializable{

	transient SearchEngineResults parent;
	
	String guid = "";
	String crc = "" ;
	
	int rawLength = 0;
	String mimetype = "" ;
	
	/** the html of the page referenced by the google url ;
	 *  could be empty if binary like pdf */
	String targetDocHtml = ""; 
	/** the home url of the respective page */
	String targetDocUrl  = "";
	
	/**  */
	String targetDocContentText = "";
	
	/**  */
	ArrayList<String> targetDocXLinks  = new ArrayList<String>() ;
	/**  */
	ArrayList<String> targetDocImgLinks  = new ArrayList<String>() ;
	
	/** by constant: normal, other search engine, google books....*/
	int typeOfPage    = -1;         

	/** the html of the list item in the results page as delivered by the search engine */
	String seHtml = "";

	/**  */
	String seQueryUrl = "" ; // google query that produced it
	
	/** the query itself */
	String seQuery ="";
	/**  */
	int seQueryPosition = -1;
	
	/** the descriptive extract as identified by the search engine (partially a function of the web site!!) */
	String seText = "";
	
	String seTitle = "";
	
	String localtmpStorageFilename = "" ;
	String requestguid = "" ;
	
	RequestFocusSpec requestFocus;
	
	ArrayList<String> words = new ArrayList<String>();
	
	
	double score = 0.0;
	boolean isScored = false;
	boolean toBeRemoved = false;
	
	
	String displayedSummaryAbstract = "";
	// ----------------------------------------------------
	
	transient PageRetrieval pageRetrieval ;
	transient PrintLog out;
	transient StringsUtil strgutil ;

	
	// ========================================================================
	public SearchEngineResultItem(SearchEngineResults parent){
		
		init(parent);
	}

	private void init(SearchEngineResults parent){
	
		guid = GUID.randomvalue() ;
		this.parent = parent;
		this.out    = parent.out ;
		this.strgutil = parent.strgutil;
		
		RequestFocusSpec rf = parent.appCommons.getModelController().getRequestFocusContext().getRequestFocusSpec();
		requestFocus = new RequestFocusSpec(rf) ;
		
		pageRetrieval = new PageRetrieval(this);
	}

	public SearchEngineResultItem(SearchEngineResultItem inSer) {
		//
		parent = inSer.getParent();
		init(parent);
		
		
		guid = inSer.guid ;
		crc = inSer.crc   ;
		
		rawLength = inSer.rawLength   ;
		mimetype = inSer.mimetype   ;
			
		targetDocHtml =  inSer.targetDocHtml   ;
		
		targetDocUrl  = inSer.targetDocUrl   ;
		targetDocContentText = inSer.targetDocContentText   ;
		
		targetDocXLinks  = new ArrayList<String>(inSer.targetDocXLinks) ;
		targetDocImgLinks  = new ArrayList<String>(inSer.targetDocImgLinks) ;

		typeOfPage = inSer.typeOfPage   ;
		seHtml = inSer.seHtml   ;
		
		seQueryUrl = inSer.seQueryUrl   ;
		seQuery = inSer.seQuery   ;
		
		seQueryPosition = inSer.seQueryPosition   ; 
		
		seText = inSer.seText   ;
		seTitle = inSer.seTitle   ;
		
		localtmpStorageFilename = inSer.localtmpStorageFilename   ;
		requestguid = inSer.requestguid   ;
		
		requestFocus = inSer.requestFocus   ;
		
		words = new ArrayList<String>(inSer.words);
		
		score = inSer.score   ;
		isScored = inSer.isScored   ;
		toBeRemoved = inSer.toBeRemoved   ;
		
		displayedSummaryAbstract = inSer.displayedSummaryAbstract   ;
		
	}

	// ========================================================================	
	

	public void finalizeContent() {
		// 
		
	}


	public String getGuid() {
		return guid;
	}
	public void setGuid(String guid) {
		this.guid = guid;
	}
	public void setRequestguid(String requestguid) {
		this.requestguid = requestguid;
	}


	public RequestFocusSpec getRequestFocus() {
		return requestFocus;
	}


	public String getCrc() {
		return crc;
	}
	public void setCrc(String crc) {
		this.crc = crc;
	}
	public int getRawLength() {
		return rawLength;
	}
	public void setRawLength(int rawLength) {
		this.rawLength = rawLength;
	}
	public String getMimetype() {
		return mimetype;
	}
	public void setMimetype(String mimetype) {
		this.mimetype = mimetype;
	}
	public String getTargetDocHtml() {
		return targetDocHtml;
	}
	public void setTargetDocHtml(String targetDocHtml) {
		this.targetDocHtml = targetDocHtml;
	}
	public String getTargetDocUrl() {
		return targetDocUrl;
	}
	public void setTargetDocUrl(String targetDocUrl) {
		this.targetDocUrl = targetDocUrl;
	}
	public String getTargetDocContentText() {
		return targetDocContentText;
	}
	public void setTargetDocContentText(String targetDocContentText) {
		this.targetDocContentText = targetDocContentText;
	}
	public ArrayList<String> getTargetDocXLinks() {
		return targetDocXLinks;
	}
	public void setTargetDocXLinks(ArrayList<String> targetDocXLinks) {
		this.targetDocXLinks = targetDocXLinks;
	}
	public ArrayList<String> getTargetDocImgLinks() {
		return targetDocImgLinks;
	}
	public void setTargetDocImgLinks(ArrayList<String> targetDocImgLinks) {
		this.targetDocImgLinks = targetDocImgLinks;
	}
	public int getTypeOfPage() {
		return typeOfPage;
	}
	public void setTypeOfPage(int typeOfPage) {
		this.typeOfPage = typeOfPage;
	}
	public String getSeHtml() {
		return seHtml;
	}
	public void setSeHtml(String seHtml) {
		this.seHtml = seHtml;
	}
	public String getSeQueryUrl() {
		return seQueryUrl;
	}
	public void setSeQueryUrl(String seQueryUrl) {
		this.seQueryUrl = seQueryUrl;
	}
	public int getSeQueryPosition() {
		return seQueryPosition;
	}
	public void setSeQueryPosition(int seQueryPosition) {
		this.seQueryPosition = seQueryPosition;
	}
	public String getSeText() {
		return seText;
	}


	public void setSeText(String seText) {
		this.seText = seText;
	}


	public String getSeTitle() {
		return seTitle;
	}


	public void setSeTitle(String seTitle) {
		this.seTitle = seTitle;
	}


	public String getLocaltmpStorageFilename() {
		return localtmpStorageFilename;
	}
	public void setLocaltmpStorageFilename(String localtmpStorageFilename) {
		this.localtmpStorageFilename = localtmpStorageFilename;
	}
	public String getRequestguid() {
		return requestguid;
	}
	
	public void setRequestFocus(RequestFocusSpec inRequestFocus) {
		
		this.requestFocus = new RequestFocusSpec (inRequestFocus);
	}
	
	public double getScore() {
		return score;
	}
	public void setScore(double score) {
		this.score = score;
	}
	public boolean isScored() {
		return isScored;
	}


	public void setScored(boolean isScored) {
		this.isScored = isScored;
	}


	public boolean isToBeRemoved() {
		return toBeRemoved;
	}


	public void setToBeRemoved(boolean toBeRemoved) {
		this.toBeRemoved = toBeRemoved;
	}


	public String getDisplayedSummaryAbstract() {
		return displayedSummaryAbstract;
	}


	public void setDisplayedSummaryAbstract(String displayedSummaryAbstract) {
		this.displayedSummaryAbstract = displayedSummaryAbstract;
	}


	public StringsUtil getStrgutil() {
		return strgutil;
	}
	public void setStrgutil(StringsUtil strgutil) {
		this.strgutil = strgutil;
	}


	public String getSeQuery() {
		return seQuery;
	}

	public void setSeQuery(String quStr) {
		this.seQuery = quStr;
	}


	public void setWordList(ArrayList<String> inWords) {
		
		if ((inWords!=null) && (inWords.size()>0)){
			if (words!=null){words.clear();}
			words = new ArrayList<String>(inWords);
		}
	}
	public ArrayList<String> getWordList() {
		return words;
	}

	public SearchEngineResults getParent() {
		return parent;
	}
	
	
	
	
	
}


class PageRetrieval implements Observer, Runnable{

	String url = "";
	String html = "";
	
	public PageRetrieval(SearchEngineResultItem searchEngineResultItem) {
		//

	}

	public void getPage( String url){
		
		
	}
	
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
		
	}
	
	
	
}
